/*
 * JFrameParqueadero.java
 *
 * Created on March 18, 2009, 5:06 AM
 */

package mpParqueadero;

import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.lang.String;

import mnParqueadero.*;
import mpParqueadero.*;

/**
 *
 * @author  Oscar Franco
 */
public class JFrameParqueadero extends javax.swing.JFrame {
    /**
     * Indicadores Puesto Parqueo
     */
    private JTextArea puestos[];
    
     /**
     * Es una referencia al parqueadero que se está mostrando
     */
    private Parqueadero parqueadero = new Parqueadero(1300);

    /** Creates new form JFrameParqueadero */
    public JFrameParqueadero() {
        initComponents();
        inicializarGrafico();
        refrescarInformacion( );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelParqueadero = new javax.swing.JPanel();
        jPanelHora = new javax.swing.JPanel();
        jLabelHora = new javax.swing.JLabel();
        jButtonAvanzar = new javax.swing.JButton();
        jPanelInformacion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldCaja = new javax.swing.JTextField();
        jTextFieldPuestos = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButtonHoraIngre = new javax.swing.JButton();
        jButtonConsultarPlaca = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButtonIngresar = new javax.swing.JButton();
        jButtonSalir = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButtoncerrar = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanelParqueadero.setBorder(javax.swing.BorderFactory.createTitledBorder("Parqueadero"));

        javax.swing.GroupLayout jPanelParqueaderoLayout = new javax.swing.GroupLayout(jPanelParqueadero);
        jPanelParqueadero.setLayout(jPanelParqueaderoLayout);
        jPanelParqueaderoLayout.setHorizontalGroup(
            jPanelParqueaderoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 847, Short.MAX_VALUE)
        );
        jPanelParqueaderoLayout.setVerticalGroup(
            jPanelParqueaderoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 178, Short.MAX_VALUE)
        );

        jPanelHora.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hora Actual", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabelHora.setText("00:00");

        javax.swing.GroupLayout jPanelHoraLayout = new javax.swing.GroupLayout(jPanelHora);
        jPanelHora.setLayout(jPanelHoraLayout);
        jPanelHoraLayout.setHorizontalGroup(
            jPanelHoraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelHoraLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabelHora)
                .addContainerGap(26, Short.MAX_VALUE))
        );
        jPanelHoraLayout.setVerticalGroup(
            jPanelHoraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelHoraLayout.createSequentialGroup()
                .addComponent(jLabelHora, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButtonAvanzar.setText("Avanzar Hora");
        jButtonAvanzar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAvanzarActionPerformed(evt);
            }
        });

        jPanelInformacion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Informacion", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Total En Caja");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Puestos Libres");

        javax.swing.GroupLayout jPanelInformacionLayout = new javax.swing.GroupLayout(jPanelInformacion);
        jPanelInformacion.setLayout(jPanelInformacionLayout);
        jPanelInformacionLayout.setHorizontalGroup(
            jPanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInformacionLayout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(jPanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldPuestos, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                    .addComponent(jTextFieldCaja, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))
                .addGap(61, 61, 61))
        );
        jPanelInformacionLayout.setVerticalGroup(
            jPanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInformacionLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldCaja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(jPanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldPuestos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Consultas"));

        jButton1.setText("Cant carros Puesto");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCantCarrosP(evt);
            }
        });

        jButtonHoraIngre.setText("Información Carro");
        jButtonHoraIngre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                horaingresoycant(evt);
            }
        });

        jButtonConsultarPlaca.setText("Placa dado puesto");
        jButtonConsultarPlaca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarPlacaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonHoraIngre)
                    .addComponent(jButtonConsultarPlaca)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonHoraIngre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonConsultarPlaca)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Vehiculos"));

        jButtonIngresar.setText("Ingresar");
        jButtonIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIngresarActionPerformed(evt);
            }
        });

        jButtonSalir.setText("Retirar");
        jButtonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButtonSalir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonIngresar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jButtonIngresar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSalir)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jButton2.setText("Abrir Parquedero");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abrir(evt);
            }
        });

        jButtoncerrar.setText("Cerrar Parquedero");
        jButtoncerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtoncerrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtoncerrar)
                .addContainerGap(15, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtoncerrar)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jToggleButton1.setText("Salir");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salir(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(81, 81, 81)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 183, Short.MAX_VALUE)
                        .addComponent(jPanelInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonAvanzar, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(128, 128, 128)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59)
                        .addComponent(jToggleButton1)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelParqueadero, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelHora, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAvanzar)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelParqueadero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(57, 57, 57))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonAvanzarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAvanzarActionPerformed
    avanzar();
}//GEN-LAST:event_jButtonAvanzarActionPerformed

private void jButtonIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIngresarActionPerformed
    ingresar( );
}//GEN-LAST:event_jButtonIngresarActionPerformed

private void jButtonSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalirActionPerformed
    salir();
}//GEN-LAST:event_jButtonSalirActionPerformed

private void horaingresoycant(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_horaingresoycant
   consultarhoraplaca();
}//GEN-LAST:event_horaingresoycant

private void jButtonConsultarPlacaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarPlacaActionPerformed
  consultarplaca();
}//GEN-LAST:event_jButtonConsultarPlacaActionPerformed

private void jButtonCantCarrosP(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCantCarrosP
  cancarpuesto(); 
}//GEN-LAST:event_jButtonCantCarrosP

private void jButtoncerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncerrarActionPerformed
 cerrarparqueadero();
}//GEN-LAST:event_jButtoncerrarActionPerformed

private void abrir(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abrir
    abrirparqueadero();
}//GEN-LAST:event_abrir

private void salir(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salir
  this.dispose();
}//GEN-LAST:event_salir

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrameParqueadero().setVisible(true);
            }
        });
    }
    
    //----------------------
    //Metodos Propios
    //----------------------
    
 /**
     * Este método se encarga de actualizar los datos que se presentan en la interfaz
     */
    public void refrescarInformacion( )
    {
        refrescarParqueadero( );
        cambiarHora( parqueadero.getHoraActual() );
        actualizarDatos( parqueadero.calcularPuestosLibres( ), parqueadero.getCaja() );
    }
    
    /**
     * Este método se encarga de actualizar la representación del parqueadero <br>
     * <b>post: </b>Se actualiza la información mostrada del parqueadero
     */
    public void refrescarParqueadero( )
    {
        String placa; 
        
        for( int i = 0; i < 90; i++ )
        {
            if( parqueadero.estaOcupado( i ) )
            {  
                puestos[ i ].setBackground( Color.RED );
                try
                {   
                    // Se envia con i + 1 pues para el método que lo recibe el cero es un valor invalido, ya que también se usa cuando se le preguntan valores a los usuarios
                    // y estos ingresan sus numeros de puestos entre 1 y 90
                    placa=parqueadero.placaporpuesto(i+1);
                    puestos[i].setText("pues: "+parqueadero.numpuesto(i)+"\n"+"plac: "+placa);
                    
                   
                }
                catch(Exception ex)
                {
                    i=90;
                    JOptionPane.showMessageDialog( this, "Lo sentimos:..."+ ex.getMessage());
                }
            }
            else
            {    
                puestos[ i ].setBackground( Color.BLUE );
                puestos[i].setText(""+(i+1));
            }
        }
    }
        
    
    /**
     * Cambia la hora presentada <br>
     * <b>post: </b>Se est� mostrando la nueva hora
     * @param hora - Nueva hora que debe mostrarse
     */
    public void cambiarHora( int hora )
    {
        jLabelHora.setText( hora + ":00" );
    }
      /**
     * Actualiza la informaci�n mostrada <br>
     * <b>post: </b>Se actualiz� la informaci�n mostrada
     * @param numVacios - N�mero de puestos vac�os
     * @param montoCaja - Cantidad de dinero en la caja
     */
    public void actualizarDatos( int numVacios, float montoCaja )
    {
        jTextFieldPuestos.setText( "" + numVacios );
        jTextFieldCaja.setText( "$ " + montoCaja );
    }
    
     /**
     * Sirve para hacer avanzar una hora el reloj del parqueadero.
     */
    public void avanzar( )
    {
        parqueadero.avanzarHoraActual();
        refrescarInformacion( );
    }
     public void ingresar( )
    {
        String placa = JOptionPane.showInputDialog( this,
                "Por favor digite la placa del carro que está ingresando" );
        if( placa != null )
        {
            try
            {
                Puesto puesto = parqueadero.entrarCarro( placa );
                JOptionPane.showMessageDialog( this, "vaya el puesto"+ puesto.getNumero());
             
            }
            catch(Exception ex)
            {
                   JOptionPane.showMessageDialog( this, "Lo sentimos:..."+ ex.getMessage());
            }
            
         }
            refrescarInformacion( );
        }
     
     /**
     * Este método sirve para sacar un carro del parqueadero. Debe pedir la placa y 
      * luego contactar al parqueadero para sacar el carro y saber cu�nto debe 
      * cancelar. Si la placa no corresponde a un carro que est� 
      * en el parqueadero entonces debe mostrar un error.
     */
    public void salir( )
    {
        String placa = JOptionPane.showInputDialog( this, 
                "Por favor digite la placa del carro que está saliendo" );
        if( placa != null )
        {
            try
            {                  
                float valor = parqueadero.sacarCarro( placa );
                 JOptionPane.showMessageDialog( this, "Valor a Pagar= $"+valor);
            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog( this, "Lo sentimos:..."+ex.getMessage());
            }
            refrescarInformacion( );
        }
        else
            JOptionPane.showMessageDialog( this, "Placa inválida: intente de nuevo..." );
    }

private void inicializarGrafico( )
    { 
        jPanelParqueadero.setLayout( new GridLayout( 5, 20 ) );       
        puestos = new JTextArea[parqueadero.calcularPuestosLibres()];
        for( int i = 0; i < parqueadero.calcularPuestosLibres( ); i++ )
        {
            puestos[ i ] = new JTextArea( );
            puestos[ i ].setText( "" + ( i + 1 ) );
            puestos[ i ].setEnabled( true );
            puestos[ i ].setEditable(false);
            puestos[ i ].setBackground( Color.BLUE );
            puestos[i].setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
            puestos[i].setForeground(new java.awt.Color(255, 255, 255));
            jPanelParqueadero.add( puestos[ i ] );
        }
        
    }


  /**
     * Permite dada la placa de un carro saber a qué horas entro y 
     * además cuantas horas lleva parqueado
     * @param placa- Placa del carro
     * @return Hora de entrada y tiempo de parqueo
     */
private void consultarhoraplaca()
{
    String placa = JOptionPane.showInputDialog( this,
                "Por favor digite la placa del carro que quiere consultar" );
     try
     {
        int horaingreso=parqueadero.verhoraIngre(placa);
        int canhoras=parqueadero.calchoras(placa);
        JOptionPane.showMessageDialog( this, "La hora de ingreso del carro fue: "+horaingreso +"\n"+"El carro lleva "+ 
                canhoras +"horas parqueado");
        
     }
     catch (Exception ex){
            JOptionPane.showMessageDialog( this, "Lo sentimos:..."+ex.getMessage());
     }
    
    
}
/**
 * Dado un numero de un puesto, da la placa del carro que tiene parqueado 
 * 
 * @param puesto Numero de  puesto
   @return Placa carro
 * /
 */

private void consultarplaca()
{
   String puestodigitado = JOptionPane.showInputDialog( this,
                "Por favor digite el puesto en el que se encuentra el carro (1-90)" );
     try
     {
        
         int puesto=Integer.parseInt(puestodigitado.trim());
         String placa=parqueadero.placaporpuesto(puesto);
         JOptionPane.showMessageDialog( this, "El número de la placa del carro es: "+placa );
        
     }
     catch (Exception ex){
            JOptionPane.showMessageDialog( this, "Lo sentimos:..."+ex.getMessage());
     } 
}


/***
 * Función que permite llevar cuantos carros se han parqueado en un puesto.
 */
private void cancarpuesto()
{
     String puestodigitado = JOptionPane.showInputDialog( this,
                "Por favor digite el puesto en el que se encuentra el carro (1-90)" );
     try
     {
        
       int puesto=Integer.parseInt(puestodigitado.trim());
       int cantcarros=parqueadero.cantcarrpuesto(puesto);
       JOptionPane.showMessageDialog( this, "La cantidad de carros en el puesto "+puesto+" es de: "+cantcarros );
        
     }
     catch (Exception ex){
            JOptionPane.showMessageDialog( this, "Lo sentimos:..."+ex.getMessage());
     } 
}

private void cerrarparqueadero()
{
    
    this.dispose();
    JFrameCerrar cerrar= new JFrameCerrar(parqueadero, this);
    cerrar.setVisible(true);
    try
    {        
        parqueadero.cerrarParquea();
    }catch(Exception ex)
    {
         JOptionPane.showMessageDialog( this, "Problemas para cerrar la ventana"+ex.getMessage());
    }
    
}
/* LLama al metodo que actualiza la hora por la hora de inicio del parqueadero, y pone en cero el contenido en caja */

private void abrirparqueadero()
{
    parqueadero.abrirParquea();
    refrescarInformacion( );
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonAvanzar;
    private javax.swing.JButton jButtonConsultarPlaca;
    private javax.swing.JButton jButtonHoraIngre;
    private javax.swing.JButton jButtonIngresar;
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JButton jButtoncerrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelHora;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanelHora;
    private javax.swing.JPanel jPanelInformacion;
    private javax.swing.JPanel jPanelParqueadero;
    private javax.swing.JTextField jTextFieldCaja;
    private javax.swing.JTextField jTextFieldPuestos;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables

}
